package org.marsdonne.auth;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.marsdonne.archives.OrganizationType;
import org.marsdonne.commons.BaseEntity;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.List;

@Getter
@Setter
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"residentId"}))
@NoArgsConstructor
public class UnionUser extends BaseEntity {

    @Column(nullable = false)
    private String residentId; //居民身份标识

    @Column(nullable = false)
    private String realName;

    @Column
    private OrganizationType organizationType;

    @Column
    private Long organizationId;

    @Column
    private String organizationLicenseCode;

    @Column
    private String organizationName;

    @OneToMany(targetEntity = PlatformUser.class, mappedBy = "unionUser")
    @PrimaryKeyJoinColumn
    private List<PlatformUser> platformUsers;

    @OneToMany(targetEntity = EndPointUser.class, mappedBy = "unionUser")
    @PrimaryKeyJoinColumn
    private List<EndPointUser> endPointUsers;

    public UnionUser(String residentId, String realName, List<PlatformUser> platformUsers, List<EndPointUser> endPointUsers) {
        this.residentId = residentId;
        this.realName = realName;
        this.platformUsers = platformUsers;
        this.endPointUsers = endPointUsers;
    }
}
